﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Frogism.Core.WorkOut;

namespace Frogism.Data {
  public class ActivityLoader:Frogism.Data.LoaderUpdateBase<Core.WorkOut.Activity,Core.WorkOut.IActivity> {

    protected override void FillObject(Frogism.Core.WorkOut.IActivity i, FriendlyReader reader) {
      i.Id = reader.Int("Id");
      i.ActivityDate = reader.Date("Date");
      i.ActivityType = (new ActivityTypeLoader()).GetById(reader.Int("ActivityTypeId"));
      i.Units = reader.Decimal("Units");

      i.Status = (ActivityStatus)reader.Int("StatusId");
    }

    public System.Collections.ObjectModel.Collection<Core.WorkOut.IActivity> GetByUserId(int id) {
      return base.ProcedureGetAll("ActivityGetByUserId", new IntegerParameter() { Name = "UserId", Value = id });
    }
    protected override string ProcNameGetById {
      get { return "ActivityGetById"; }
    }

    protected override Frogism.Core.WorkOut.IActivity GetEmptyObject() {
      return new Core.WorkOut.Activity();
    }

    protected override string ProcNameGetAll {
      get { throw new NotImplementedException(); }
    }
    protected override string ProcNameDelete {
      get { return "ActivityDelete"; }
    }

    protected override void FillParameters(System.Data.SqlClient.SqlCommand cmd, IActivity Obj) {
      AddIntParam(cmd, "UserId", 1);
      AddDateParam(cmd, "ActivityDate", Obj.ActivityDate);
      AddIntParam(cmd, "ActivityTypeId", Obj.ActivityType.Id);
      AddIntParam(cmd, "StatusId", (int)Obj.Status);
      AddDecimalParam(cmd, "Units", Obj.Units);
    }

    protected override string ProcNameSave {
      get { return "ActivityUpdate"; }
    }

    protected override string ProcNameCreate {
      get { return "ActivityInsert"; }
    }
  }
}
